﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Browse_ProvenanceDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["query"] != null)
        {
            Int32 SelectedThreadID = Int32.Parse(Request.QueryString["query"]);
           
            using (PublicCatalogDataContext db = new PublicCatalogDataContext())
            {

                var myProvenance = from Provenance in db.Provenances
                                          where Provenance.ProvenanceId == SelectedThreadID
                                          select new { Provenance.ProvenanceName };
           
                foreach (var q in myProvenance)
                {
                    var ProvenanceName = q.ProvenanceName;
                    Label1.Text = q.ProvenanceName;
                }
                
            }

            using (PublicCatalogDataContext db = new PublicCatalogDataContext())
            {
                var myProvenanceVariant = from ProvenanceVariant in db.ProvenanceVariants
                                          where ProvenanceVariant.ProvenanceId == SelectedThreadID
                                          select new { ProvenanceVariant.ProvenanceVariantName };
                foreach (var a in myProvenanceVariant)
                {
                    if (a.ProvenanceVariantName != null)
                    {
                        Repeater1.Visible = true;
                        Label2.Visible = true;
                        Repeater1.DataSource = myProvenanceVariant;
                        Repeater1.DataBind();
                    }
                }
             
                
            }

            using (PublicCatalogDataContext db = new PublicCatalogDataContext())
            {
                var myProvenance = from a in db.Provenances
                                   where a.ProvenanceId == SelectedThreadID
                                   select new { a.ProvenanceGeneralNote, a.ProvenanceAdministrativeHistory };
                foreach (var a in myProvenance)
                {
                    if (a.ProvenanceGeneralNote == null)
                    {
                        Literal3.Visible = false;
                        Label4.Visible = false;
                    }
                    Literal3.Text = a.ProvenanceGeneralNote;
                    Repeater2.DataSource = myProvenance;
                    Repeater2.DataBind();
                }
            }

            using (PublicCatalogDataContext db = new PublicCatalogDataContext())
            {
                //*****Need data validation to not disply Series that are restricted.
                var mySeries = from b in db.Series
                               where b.ProvenanceId == SelectedThreadID
                               select new { b.SeriesTitle, b.SeriesId};
                Repeater3.DataSource = mySeries;
                Repeater3.DataBind();
            }
            if (Request.QueryString["query"] == null)
            {
                //Need to add error handling
            }
        }
    }
}
